package DataSetPackage;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.osdtsystem.utils.Storage;

/**
 *
 * @author Martin Haulrich
 */
public class DataSetStorage implements DataSet {

    /**
     * List of data. Deleted data is replaced with null;
     */
    List<List<String>> data;

    /**
     * Set of dataIDs that are still in the data set.
     */
    Set<Integer> activeIDs;

    public DataSetStorage(Storage storage) {

        data = storage.<List<String>>newList((Object[]) null);
        activeIDs = storage.<Integer>newSet((Object[]) null);
    }

    @Override
    public Collection<Integer> getIDs() {

        return activeIDs;
    }

    @Override
    public Collection<List<String>> getData() {
        return data;
    }

    @Override
    public Integer add(List<String> features) {
        Integer ID = data.size();
        data.add(features);
        activeIDs.add(ID);
        return ID;
    }

    @Override
    public List<String> getFeatures(Integer dataID) {

        return data.get(dataID);
    }

    @Override
    public void remove(Integer dataID) {
        data.set(dataID, null);
        activeIDs.remove(dataID);
    }

    @Override
    public int size() {
        return activeIDs.size();
    }
}
